//
//  AcceptOrderVC.m
//  Zhiche-Carriage
//
//  Created by 王亚陆 on 16/6/14.
//  Copyright © 2016年 LeeBruce. All rights reserved.
//

#import "AcceptOrderVC.h"
#import <Masonry.h>
#import "Common.h"
#import "QuoteCell.h"
#import "BequoteVC.h"
#import "AcceptDetailVC.h"
@interface AcceptOrderVC ()
{
    Common * com;
    UIView * nav;
    UITableView * table;
    NSMutableArray * dataSouceArr;
    int loadState;
}
@property (nonatomic,strong) UIButton * btn1;
@property (nonatomic,strong) UIButton * btn2;

@end

@implementation AcceptOrderVC

- (void)viewDidLoad {
    [super viewDidLoad];
    com = [[Common alloc]init];
    
    self.view.backgroundColor = WhiteColor;
    dataSouceArr = [[NSMutableArray alloc]init];
    
    nav = [self createNav:@"接单"];
    [self.view addSubview:nav];
    
    loadState = 1;
//    [self createBtn];
//    [self createTable];
//    [self createDate:loadState];
    
}
/*
-(void)createBtn{
    
    _btn1 = [com createBtn:@"待报价" andFont:FontOfSize14 andTag:1 and:self action:@selector(pressBtn:) andColor:BlackColor];
    _btn1.backgroundColor = [UIColor cyanColor];
    [self.view addSubview:_btn1];
    _btn2 = [com createBtn:@"已报价" andFont:FontOfSize14 andTag:2 and:self action:@selector(pressBtn:) andColor:BlackColor];
    [self.view addSubview:_btn2];
    [_btn1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left);
        make.top.equalTo(nav.mas_bottom).with.offset(0);
        make.size.mas_equalTo(CGSizeMake(Main_Width/2, 33*kHeight));
    }];
    [_btn2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view.mas_right);
        make.top.equalTo(nav.mas_bottom).with.offset(0);
        make.size.mas_equalTo(CGSizeMake(Main_Width/2, 33*kHeight));
    }];
}

-(void)pressBtn:(UIButton*)sender{
    
    if (sender.tag == 1) {
        loadState = 1;
        [self createDate:1];
        _btn1.backgroundColor = [UIColor cyanColor];
        _btn2.backgroundColor = WhiteColor;
    }else{
        loadState = 2;
        [self createDate:2];
        _btn2.backgroundColor = [UIColor cyanColor];
        _btn1.backgroundColor = WhiteColor;
    }
}
-(void)createDate:(int)number{
    
    int pageNo = 1;
    int pageSize = 10;
    
    NSString * string = nil;
    if (number == 1) {
        string = [NSString stringWithFormat:@"%@?pageNo=%d&pageSize=%d",bequoted_Url,pageNo,pageSize];
    }else{
        string = [NSString stringWithFormat:@"%@?pageNo=%d&pageSize=%d",already_Url,pageNo,pageSize];
    }
    
    [Common requestWithUrlString:string contentType:@"application/json" finished:^(id responseObj){
        
        NSLog(@"%@",responseObj);

        dataSouceArr = nil;
        if (loadState ==1) {
            dataSouceArr = responseObj[@"data"][@"orders"];
        }else{
            dataSouceArr = responseObj[@"data"][@"quotes"];
        }
        [table reloadData];
        
    } failed:^(NSString *errorMsg) {
        NSLog(@"%@",errorMsg);
    }];
}

-(void)createTable{
    
    
    table = [[UITableView alloc]initWithFrame:CGRectMake(0, 98*kHeight, Main_Width,Main_height-98*kHeight) style:UITableViewStylePlain];
    [table setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    table.delegate = self;
    table.dataSource = self;
    [self.view addSubview:table];

}



-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    static NSString *str=@"str";
    
    QuoteCell * cell =  [tableView dequeueReusableCellWithIdentifier:str];
    if (cell ==nil) {
        cell = [[QuoteCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    NSLog(@"%ld",indexPath.row);
    if (loadState == 1) {
        [cell showInfo:dataSouceArr[indexPath.row] andLoad:loadState];
        cell.Btn.hidden = NO;
        cell.Btn.tag = indexPath.row;
        [cell.Btn addTarget:self action:@selector(pressBtn2:) forControlEvents:UIControlEventTouchUpInside];
    }else{
        cell.Btn.hidden = YES;
        [cell showInfo:dataSouceArr[indexPath.row] andLoad:loadState];
    }
    return cell;
}
-(void)pressBtn2:(UIButton*)sender{
 
    
    BequoteVC * bequote = [[BequoteVC alloc]init];
    bequote.orderid = dataSouceArr[sender.tag][@"id"];
    [self.navigationController pushViewController:bequote animated:YES];
    
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return  (loadState ==1 )?190*kHeight:145*kHeight;
    
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return dataSouceArr.count;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    AcceptDetailVC * detail = [[AcceptDetailVC alloc]init];
    if (loadState == 1) {
        detail.ID = dataSouceArr[indexPath.row][@"id"];
    }else{
        detail.ID = dataSouceArr[indexPath.row][@"order"][@"id"];
    }
    [self.navigationController pushViewController:detail animated:YES];
}

*/





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
